import { getPlatformConfig } from '@/api/face/platform'

const platform = {
  state: {
    platformName: '',
    platformLogo: '',
    platformCopyRight: '',
  },

  mutations: {
    SET_PLATFORMNAME: (state, platformName) => {
      state.platformName = platformName
    },
    SET_PLATFORMLOGO: (state, platformLogo) => {
      state.platformLogo = platformLogo
    },
    SET_PLATFORMCOPYRIGHT: (state, platformCopyRight) => {
      state.platformCopyRight = platformCopyRight
    },
  },

  actions: {

    // 获取平台信息
    GetPlatformInfo({ commit, state }) {
      return new Promise((resolve, reject) => {
        getPlatformConfig().then(res => {
          let platformName = res.data.platformName;
          let platformLogo = res.data.platformLogo;
          let platformCopyRight = res.data.platformCopyRight;
          if(!platformName){
            platformName = '实训平台'
          }
          if(!platformLogo){
            platformLogo = require("@/assets/logo/logo.png")
          }else{
            platformLogo = process.env.VUE_APP_BASE_API + platformLogo;
          }
          if(!platformCopyRight){
            platformCopyRight = '实训平台@copyright'
          }
         
          commit('SET_PLATFORMNAME', platformName)
          commit('SET_PLATFORMLOGO', platformLogo)
          commit('SET_PLATFORMCOPYRIGHT',platformCopyRight)
          resolve(res)
        }).catch(error => {
          reject(error)
        })
      })
    },
  }
}

export default platform
